package com.gitee.srurl.oid.domain;

import com.gitee.srurl.oid.store.FileOidStore;
import com.gitee.srurl.oid.store.IOidStore;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

/**
 * @author zxw
 * @date 2023/5/7 17:47
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class OidData {

    /**
     * 机器ID
     */
    private Long workerId;

    /**
     * 是否开启批量获取ID
     */
    private Boolean useBatch;

    /**
     * 批量获取数量
     */
    private Integer batchNum;

    /**
     * id存储
     */
    private IOidStore oidStore;

    public static OidData.OidDataBuilder builder() {
        return new OidData.OidDataBuilder();
    }

    @ToString
    public static class OidDataBuilder {

        private Long workerId;
        private Boolean useBatch;
        private Integer batchNum;
        private IOidStore oidStore;

        private OidDataBuilder() {
        }

        public OidData.OidDataBuilder workerId(final Long workerId) {
            this.workerId = workerId;
            return this;
        }

        public OidData.OidDataBuilder useBatch(final Boolean useBatch) {
            this.useBatch = useBatch;
            return this;
        }

        public OidData.OidDataBuilder batchNum(final Integer batchNum) {
            this.batchNum = batchNum;
            return this;
        }

        public OidData.OidDataBuilder oidStore(final IOidStore oidStore) {
            this.oidStore = oidStore;
            return this;
        }

        public OidData build() {
            return new OidData(
                    this.workerId == null ? 0L : this.workerId,
                    this.useBatch != null && useBatch,
                    this.batchNum == null ? 1 : batchNum,
                    this.oidStore == null ? new FileOidStore() : this.oidStore
            );
        }
    }
}
